using System.Data;
using System.Data.SQLite;
using Model;

namespace DAL {
    public class ProductDAL {
        private ProductDAL() { }
        private static ProductDAL instance = new ProductDAL();

        public static ProductDAL GetInstance() {
            return instance;
        }
        
        public DataTable SelectAllProduct() {
            return SqlHelper.GetDataTable(
                new SQLiteCommand("select * from ProductInfo where DelFlag = 0"));
        }

        public DataTable SelectByName(Product product) {
            return SqlHelper.GetDataTable(new SQLiteCommand("select * from ProductInfo where ProName like @name and DelFlag = 0") {
                Parameters = {
                    new SQLiteParameter("@name", "%" + product.ProName + "%")
                }
            });
        }

        public DataTable SelectByCatID(Product product) {
            return SqlHelper.GetDataTable(new SQLiteCommand("select * from ProductInfo where CatId = @catId and DelFlag = 0") {
                Parameters = {
                    new SQLiteParameter("@catId", product.CatId)
                }
            });
        }

        public void Update(Product product) {
            SqlHelper.Update(new SQLiteCommand("update ProductInfo set ProStock=@proStock where ProId=@proId") {
                Parameters = {
                    new SQLiteParameter("@proStock", product.ProStock),
                    new SQLiteParameter("@proId", product.ProId)
                }
            });
        }
    }
}